﻿using System;
using System.Linq;
using System.Windows.Forms;
using 右下角弹窗.DiagShow;

namespace LD.Host
{
    public partial class FrmLogin : Form
    {
        public FrmLogin()
        {
            InitializeComponent();
            this.FormClosed += FrmLogin_FormClosed;
            this.Load += FrmLogin_Load;
        }

        private void FrmLogin_FormClosed(object sender, FormClosedEventArgs e)
        {
            Console.WriteLine("a");
        }

        private void FrmLogin_Load(object sender, EventArgs e)
        {
            foreach (var item in Enum.GetNames(typeof(UserType)))
            {
                this.cob_user.Items.Add(item);
                this.cob_user.SelectedIndex = 0;
            };
            this.txt_pwd.Focus();
        }

        private void FrmLogin_Shown(object sender, EventArgs e)
        {
            foreach (var item in Enum.GetNames(typeof(UserType)))
            {
                this.cob_user.Items.Add(item);
                this.cob_user.SelectedIndex = 0;
            };
            this.txt_pwd.Focus();
        }

        private void btn_login_Click(object sender, EventArgs e)
        {
            Login();
        }

        private void txt_pwd_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Login();
            }
        }
        private void Login()
        {
            TB_User user = Appbus.User.GetList.Where(p => p.Name == this.cob_user.Text).FirstOrDefault();
            if (!user.Pwd.Equals(this.txt_pwd.Text))
            {
                Dialog dialog = new Dialog();
                dialog.Warning("密码错误");
                return;
            }
            Appbus.User.CurrentUser = user;
            this.Close();
        }
    }
}
